package com.allm.ai.common.exception;

import lombok.Getter;

/**
 * 业务异常类
 *
 * @author com.enplatform
 * @since 1.0.0
 */
@Getter
public class BusinessException extends RuntimeException {

    /**
     * 常用HTTP状态码常量
     */
    public static final int BAD_REQUEST = 400;
    public static final int UNAUTHORIZED = 401;
    public static final int FORBIDDEN = 403;
    public static final int NOT_FOUND = 404;
    public static final int INTERNAL_SERVER_ERROR = 500;

    /**
     * 错误代码
     */
    private final String code;

    /**
     * HTTP状态码
     */
    private final int httpStatus;

    /**
     * 构造业务异常（默认400状态码）
     *
     * @param code 错误代码
     * @param message 错误消息
     */
    public BusinessException(String code, String message) {
        super(message);
        this.code = code;
        this.httpStatus = BAD_REQUEST;
    }

    /**
     * 构造业务异常（指定HTTP状态码）
     *
     * @param code 错误代码
     * @param message 错误消息
     * @param httpStatus HTTP状态码
     */
    public BusinessException(String code, String message, int httpStatus) {
        super(message);
        this.code = code;
        this.httpStatus = httpStatus;
    }

    /**
     * 构造业务异常（带原因异常）
     *
     * @param code 错误代码
     * @param message 错误消息
     * @param cause 原因异常
     */
    public BusinessException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.httpStatus = BAD_REQUEST;
    }

    /**
     * 构造业务异常（带原因异常和HTTP状态码）
     *
     * @param code 错误代码
     * @param message 错误消息
     * @param cause 原因异常
     * @param httpStatus HTTP状态码
     */
    public BusinessException(String code, String message, Throwable cause, int httpStatus) {
        super(message, cause);
        this.code = code;
        this.httpStatus = httpStatus;
    }
}
